package org.bluedream.core.module.dao.bill.stkIn.dtl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.bluedream.core.module.entity.bill.stkIn.dtl.StkInBackDtl;

/**
 * @ClassName StkInBackDtlDao
 * @Description TODO
 * @Author foxsand
 * @Data 14:53
 * @Version
 */
public interface StkInBackDtlDao extends BaseMapper<StkInBackDtl> {
    @Override
    @Select("select stkInBackDtl.bill_type as billType , stkInBackDtl.bill_num as billNum , stkInBackDtl.code as code, b.barcode as barcode, b.name as name, stkInBackDtl.qty as qty ," +
            " stkInBackDtl.id as id , stkInBackDtl.create_by as createBy , stkInBackDtl.create_date as createDate , stkInBackDtl.update_by as updateBy , " +
            " stkInBackDtl.update_date as updateDate , " +
            " stkInBackDtl.status as status , stkInBackDtl.remarks as remarks , " +
            "   case " +
            "       when mod(stkInBackDtl.qty , b.qpc) = 0 then to_char(stkInBackDtl.qty / b.qpc)  " +
            "       when mod(stkInBackDtl.qty , b.qpc) != 0  and stkInBackDtl.qty/b.qpc = 0 then to_char(floor(stkInBackDtl.qty/b.qpc))||'+'||to_char(stkInBackDtl.qty) " +
            "       when mod(stkInBackDtl.qty , b.qpc) != 0  and stkInBackDtl.qty/b.qpc != 0 then to_char(floor(stkInBackDtl.qty/b.qpc))||'+'||to_char(stkInBackDtl.qty - b.qpc) end as qtyStr , " +
            "b.qpc as qpc , b.qpc_str as qpcStr , b.unit as unit , b.spec as spec , stkInBackDtl.oprice as oprice , stkInBackDtl.total as total " +
            "from StkInBackDtl stkInBackDtl , goods b " +
            " ${ew.customSqlSegment} and stkInBackDtl.code = b.code ")
    IPage<StkInBackDtl> selectPage(IPage<StkInBackDtl> page, @Param("ew") Wrapper<StkInBackDtl> wrapper);
}
